<!DOCTYPE html>
<html xmlns:th="https//www.thymeleaf.org">
	<head>
		<title>管理商品</title>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0">
		<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet" type="text/css"/>
		<script th:src="@{/js/jquery-3.4.1.min.js}" type="text/javascript"></script>
		<script th:src="@{/js/bootstrap.min.js}" type="text/javascript"></script>
		<script th:src="@{/js/vue.min.js}" type="text/javascript"></script>
		<script th:src="@{/js/site.js}" type="text/javascript"></script>
	</head>

	<body>
		<div class="container col-11">
			<div class="row">
				<h5>商品管理</h5>
			</div>
		<div class ="row" th:unless="${#strings.isEmpty(ok)}">
			<p class="alert alert-success" th:text="${ok}"></p>
		</div>
			<div class="row">
				<form class="form-row" th:action="@{/listproducts}" id="form1"  th:object="${search}" method="post">
					<div class="form-group">
						<label>关键字</label>
						<input type="text" placeholder="请输入关键字进行搜索" th:field="*{keyword}">										
					</div>
					<div class="form-group">
						<input type="submit" class="btn btn-primary" value="搜索">
						<a th:href="@{/editproduct}" class="btn btn-primary">添加内容</a> 
						<input type="hidden" name="cids" value="" id="deletecids">
						<button type="button" class="btn btn-danger delbtns">删除</button>
					</div>
				</form>
			</div>
			<div class="row">
				<table class="table">
					<thead>
						<tr>
							<th>序号</th>
							<th>名称</th>
							<th>发布者</th>
							<th>发布日期</th>
							<th>是否有效</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<tr th:each="p:${pages.content}">
							<td>
								<input type="checkbox" th:value="${p.pid}" class="puid">
								<span th:text="${pStat.count}"></span></td>
							<td th:text="${p.name}"></td>
							<td th:text="${p.user==null?'':p.user.account}"></td>
							<td th:text="${p.pubdate}"></td>
							<td th:text="${p.validstate}"></td>
							<td>
							<a th:href="@{|/validproduct/${p.pid}|}">通过/取消</a>
							<a th:href="@{|/editproduct/${p.pid}|}">编辑</a>
							<a th:href="@{|/deleteproduct/${p.pid}|}" class="delbtn">删除</a></td>
						</tr>
					</tbody>
				</table>
			</div>
			<div class="row" th:fragment="pager">
				<nav ><!-- 分页碎片需要的数据：1、查询结果数据用pages作为关键字，且是分页查询。2、当前网址必须是查询页面 -->
					<ul class="pagination">
						<li class="page-item" th:each="p : ${#numbers.sequence(1,pages.totalPages)}">
							<a href="javascript:void(0);" th:page="${p-1}" class="page-link pagelink" th:text="${p}"></a>
						</li>
						<!-- '?page='+${p-1}+'&size=1' -->
					</ul>
				</nav>
				<script type="text/javascript">
					$(".pagelink").click(function(){
						var f = $("#form1");
						var p = $("<input type='hidden' name='page'>");
						$(p).val($(this).attr("page"));
						//var s = $("<input type='hidden' name='size' value='1'>");
						//$(s).appendTo(f);
						$(p).appendTo(f);
						$(f).submit();
						return false;
					});
					
				</script>
			</div>
		</div>
	</body>
</html>